﻿using System.Linq;
using XRM.Security.DataAccess.Context;
using XRM.Security.DataAccess.Enums;
using XRM.Security.DataAccess.Models;

namespace XRM.Security.DataAccess.Repositories.Impl
{
    public class RequestRepository : BaseRepository<Request>
    {
        public RequestRepository(IDbContext dbContext) : base(dbContext)
        {}

        public int GetNewRequestNumber()
        {
            var lastNumber = GetAll().Max( s => (int?)s.Number ) ?? 0;
            return lastNumber + 1;
        }        

        public IQueryable<Request> GetOpenRequests()
        {
            return GetAll( s => s.Status == (int)RequestStatus.InWork || s.Status == (int)RequestStatus.InPart );
        }
    }
}
